convert all readFile, writeFile, and appendFile to close-on-exec safe versions
authorJoey Hess <joeyh@joeyh.name>
Fri, 5 Sep 2025 19:37:13 +0000 (15:37 -0400)
committerJoey Hess <joeyh@joeyh.name>
Fri, 5 Sep 2025 19:44:32 +0000 (15:44 -0400)
Even in the Build system. This allows grepping to make sure that there
are none left un-converted:

git grep "writeFile" |grep -v F\\.| grep -v doc/|grep -v writeFileString | grep -v writeFileProtected |grep -v Utility/FileIO
git grep "readFile" |grep -v F\\.| grep -v doc/|grep -v readFileString |grep -v Utility/FileIO
git grep "appendFile" |grep -v F\\.| grep -v doc/|grep -v appendFileString |grep -v Utility/FileIO

Might be nice to automate that to prevent future mistakes...

Sponsored-by: the NIH-funded NICEMAN (ReproNim TR&D3) project
58 files changed:
Annex/Content.hs
Annex/Fixup.hs
Annex/Path.hs
Annex/Sim.hs
Annex/Ssh.hs
Annex/YoutubeDl.hs
Assistant/DaemonStatus.hs
Assistant/Install.hs
Assistant/Install/AutoStart.hs
Assistant/Restart.hs
Assistant/Ssh.hs
Assistant/Upgrade.hs
Assistant/WebApp/Configurators/Local.hs
Assistant/WebApp/Control.hs
Assistant/WebApp/Documentation.hs
Build/Configure.hs
Build/DesktopFile.hs
Build/DistributionUpdate.hs
Build/LinuxMkLibs.hs
Build/NullSoftInstaller.hs
Build/Standalone.hs
Build/TestConfig.hs
Build/Version.hs
Command/FuzzTest.hs
Command/ImportFeed.hs
Command/Map.hs
Command/Sim.hs
Command/Vicfg.hs
Command/WebApp.hs
Config/Files.hs
Config/Files/AutoStart.hs
Config/Smudge.hs
Database/Keys.hs
Git/Construct.hs
Git/Hook.hs
Git/Objects.hs
Git/Repair.hs
Logs/File.hs
Logs/FsckResults.hs
Logs/Restage.hs
Logs/Schedule.hs
Logs/Transfer.hs
Logs/View.hs
Remote/Directory/LegacyChunked.hs
Remote/Tahoe.hs
Test.hs
Test/Framework.hs
Upgrade/V2.hs
Upgrade/V7.hs
Utility/Daemon.hs
Utility/FileMode.hs
Utility/FreeDesktop.hs
Utility/InodeCache.hs
Utility/LockFile/PidLock.hs
Utility/Misc.hs
Utility/Shell.hs
Utility/Tmp.hs
Utility/Tor.hs

index 15d58e2e26674ae298423dab20f6fd4b9f480b0c..638390b2bf2678b2360677db9c509663e3eb0954 100644 (file)
@@ -276,8 +276,7 @@ winLocker :: (LockFile -> IO (Maybe LockHandle)) -> ContentLocker
 winLocker takelock _ (Just lockfile) = 
        let lck = do
                modifyContentDir lockfile $
-                       void $ liftIO $ tryIO $
-                               writeFile (fromOsPath lockfile) ""
+                       void $ liftIO $ tryIO $ writeFileString lockfile ""
                liftIO $ takelock lockfile
        in (lck, Nothing)
 -- never reached; windows always uses a separate lock file
@@ -991,7 +990,7 @@ withTmpWorkDir key action = do
        -- clean up gitAnnexTmpWorkDir for those it finds.
        obj <- prepTmp key
        unlessM (liftIO $ doesFileExist obj) $ do
-               liftIO $ writeFile (fromOsPath obj) ""
+               liftIO $ writeFileString  obj ""
                setAnnexFilePerm obj
        let tmpdir = gitAnnexTmpWorkDir obj
        createAnnexDirectory tmpdir
@@ -1083,7 +1082,7 @@ writeContentRetentionTimestamp key rt t = do
                readContentRetentionTimestamp rt >>= \case
                        Just ts | ts >= t -> return ()
                        _ -> replaceFile (const noop) rt $ \tmp ->
-                               liftIO $ writeFile (fromOsPath tmp) $ show t
+                               liftIO $ writeFileString tmp $ show t
   where
        lock = takeExclusiveLock
        unlock = liftIO . dropLock
index 1e245668f34ec2c6b6917d327ea4100118cc3000..c6b1bf50423ae34b37323ab8357b48182bab171b 100644 (file)
@@ -1,6 +1,6 @@
 {- git-annex repository fixups
  -
- - Copyright 2013-2020 Joey Hess <id@joeyh.name>
+ - Copyright 2013-2025 Joey Hess <id@joeyh.name>
  -
  - Licensed under the GNU AGPL version 3 or higher.
  -}
@@ -9,29 +9,14 @@
 
 module Annex.Fixup where
 
+import Common
 import Git.Types
 import Git.Config
 import Types.GitConfig
-import Utility.Path
-import Utility.Path.AbsRel
-import Utility.SafeCommand
-import Utility.Directory
-import Utility.Exception
-import Utility.Monad
-import Utility.SystemDirectory
-import Utility.OsPath
 import qualified Utility.RawFilePath as R
-import Utility.PartialPrelude
 import qualified Utility.OsString as OS
 
-import System.IO
-import Data.List
-import Data.Maybe
-import Control.Monad
-import Control.Monad.IfElse
 import qualified Data.Map as M
-import Control.Applicative
-import Prelude
 
 fixupRepo :: Repo -> GitConfig -> IO Repo
 fixupRepo r c = do
@@ -132,11 +117,11 @@ fixupUnusualRepos r@(Repo { location = Local { worktree = Just w, gitdir = d } }
        -- git-worktree sets up a "commondir" file that contains
        -- the path to the main git directory.
        -- Using --separate-git-dir does not.
-       commondirfile = fromOsPath (d </> literalOsPath "commondir")
+       commondirfile = d </> literalOsPath "commondir"
        
        readcommondirfile = catchDefaultIO Nothing $
                fmap toOsPath . headMaybe . lines
-                       <$> readFile commondirfile
+                       <$> readFileString commondirfile
 
        setworktreepath r' = readcommondirfile >>= \case
                Just gd -> return $ r'
index 802ab9c0430709f36f737481dbbcc071755a771c..6db939e084422b2bc431788d24475513049c3590 100644 (file)
@@ -65,7 +65,7 @@ programPath = go =<< getEnv "GIT_ANNEX_DIR"
 readProgramFile :: IO (Maybe OsPath)
 readProgramFile = catchDefaultIO Nothing $ do
        programfile <- programFile
-       fmap toOsPath . headMaybe . lines <$> readFile (fromOsPath programfile)
+       fmap toOsPath . headMaybe . lines <$> readFileString programfile
 
 cannotFindProgram :: IO a
 cannotFindProgram = do
index 823d991ad2226cdfb906af3d60e08061125db350..fa80b94e220f03cc4bf64305033082a3cf7df29b 100644 (file)
@@ -1356,16 +1356,15 @@ suspendSim st = do
        let st'' = st'
                { simRepoState = M.map freeze (simRepoState st')
                }
-       let statefile = fromOsPath $ 
-               toOsPath (simRootDirectory st'') </> literalOsPath "state"
-       writeFile statefile (show st'')
+       let statefile = toOsPath (simRootDirectory st'') </> literalOsPath "state"
+       writeFileString statefile (show st'')
   where
        freeze :: SimRepoState SimRepo -> SimRepoState ()
        freeze rst = rst { simRepo = Nothing }
 
 restoreSim :: OsPath -> IO (Either String (SimState SimRepo))
 restoreSim rootdir = 
-       tryIO (readFile statefile) >>= \case
+       tryIO (readFileString statefile) >>= \case
                Left err -> return (Left (show err))
                Right c -> case readMaybe c :: Maybe (SimState ()) of
                        Nothing -> return (Left "unable to parse sim state file")
@@ -1379,7 +1378,7 @@ restoreSim rootdir =
                                        }
                                return (Right st'')
   where
-       statefile = fromOsPath $ rootdir </> literalOsPath "state"
+       statefile = rootdir </> literalOsPath "state"
        thaw st (u, rst) = tryNonAsync (thaw' st u) >>= return . \case
                Left _ -> (u, rst { simRepo = Nothing })
                Right r -> (u, rst { simRepo = Just r })
index a0e4ff9319c18c39c443eda5b9dfb0a1f3c3f630..2a482dbc3cf92f7edacc9f193dd26d0c6a1adb9e 100644 (file)
@@ -484,4 +484,4 @@ sshAskPassEnv :: String
 sshAskPassEnv = "GIT_ANNEX_SSHASKPASS"
 
 runSshAskPass :: FilePath -> IO ()
-runSshAskPass passfile = putStrLn =<< readFile passfile
+runSshAskPass passfile = putStrLn =<< readFileString (toOsPath passfile)
index 5b3fbd7158d308f9473ea439e331502091f36173..6c132959551f9967036cc59c1a4ee22ba57b03cb 100644 (file)
@@ -94,7 +94,7 @@ youtubeDl' url workdir p uo
        nofiles = Left $ youtubeDlCommand ++ " did not put any media in its work directory, perhaps it's been configured to store files somewhere else?"
        toomanyfiles fs = Left $ youtubeDlCommand ++ " downloaded multiple media files; git-annex is only able to deal with one per url: " ++ show fs
        downloadedfiles = liftIO $ 
-               (nub . lines <$> readFile (fromOsPath filelistfile))
+               (nub . lines <$> readFileString filelistfile)
                        `catchIO` (pure . const [])
        workdirfiles = liftIO $ filter (/= filelistfile) 
                <$> (filterM doesFileExist =<< dirContents workdir)
index eeb40605ea569c1bfb983ff995db7b299d89431b..80f18b69966b20273a0aa615ab1bdc27daf89b7a 100644 (file)
@@ -132,7 +132,7 @@ writeDaemonStatusFile file status =
                ]
 
 readDaemonStatusFile :: FilePath -> IO DaemonStatus
-readDaemonStatusFile file = parse <$> newDaemonStatus <*> readFile file
+readDaemonStatusFile file = parse <$> newDaemonStatus <*> readFileString (toOsPath file)
   where
        parse status = foldr parseline status . lines
        parseline line status
index 750b4a9adc1981a9d467c3605bec6f52093bedc4..c5710ff213d8f4b1b6c35e0ef764b1e79ec8f98a 100644 (file)
@@ -57,7 +57,7 @@ ensureInstalled = ifM (isJust <$> getEnv "GIT_ANNEX_PACKAGE_INSTALL")
                let program = base </> literalOsPath "git-annex"
                programfile <- programFile
                createDirectoryIfMissing True (parentDir programfile)
-               writeFile (fromOsPath programfile) (fromOsPath program)
+               writeFileString programfile (fromOsPath program)
 
 #ifdef darwin_HOST_OS
                autostartfile <- userAutoStart osxAutoStartLabel
@@ -70,7 +70,7 @@ ensureInstalled = ifM (isJust <$> getEnv "GIT_ANNEX_PACKAGE_INSTALL")
                                let bootfile = toOsPath home </> literalOsPath ".termux" </> literalOsPath "boot" </> literalOsPath "git-annex"
                                unlessM (doesFileExist bootfile) $ do
                                        createDirectoryIfMissing True (takeDirectory bootfile)
-                                       writeFile (fromOsPath bootfile) "git-annex assistant --autostart"
+                                       writeFileString bootfile "git-annex assistant --autostart"
                        , do
                                menufile <- desktopMenuFilePath "git-annex" <$> userDataDir
                                icondir <- iconDir <$> userDataDir
@@ -125,7 +125,7 @@ installFileManagerHooks program = unlessM osAndroid $ do
        userdata <- userDataDir
        let kdeServiceMenusdir = userdata </> literalOsPath "kservices5" </> literalOsPath "ServiceMenus"
        createDirectoryIfMissing True kdeServiceMenusdir
-       writeFile (fromOsPath (kdeServiceMenusdir </> literalOsPath "git-annex.desktop"))
+       writeFileString (kdeServiceMenusdir </> literalOsPath "git-annex.desktop")
                (kdeDesktopFile actions)
   where
        genNautilusScript scriptdir action =
@@ -136,7 +136,7 @@ installFileManagerHooks program = unlessM osAndroid $ do
                        ]
        scriptname action = "git-annex " ++ action
        installscript f c = whenM (safetoinstallscript f) $ do
-               writeFile (fromOsPath f) c
+               writeFileString f c
                modifyFileMode f $ addModes [ownerExecuteMode]
        safetoinstallscript f = catchDefaultIO True $
                elem (encodeBS autoaddedcomment) . fileLines'
index 366e2027312ea707c44ffb3825c78d9bec9a79d7..c689f9d2fde2a05fc4c25645808745037c14277b 100644 (file)
@@ -23,7 +23,7 @@ installAutoStart :: String -> OsPath -> IO ()
 installAutoStart command file = do
 #ifdef darwin_HOST_OS
        createDirectoryIfMissing True (parentDir file)
-       writeFile (fromOsPath file) $ genOSXAutoStartFile osxAutoStartLabel command
+       writeFileString file $ genOSXAutoStartFile osxAutoStartLabel command
                ["assistant", "--autostart"]
 #else
        writeDesktopMenuFile (fdoAutostart command) file
index 658d1ddf1800f4c30a2fa3398aaa06ee165e722d..58a17c12a218caea0d95656060c998a567dcafa2 100644 (file)
@@ -79,7 +79,7 @@ newAssistantUrl repo = do
                r <- Git.Config.read =<< Git.Construct.fromPath repo
                waiturl $ gitAnnexUrlFile r
        waiturl urlfile = do
-               v <- tryIO $ readFile (fromOsPath urlfile)
+               v <- tryIO $ readFileString urlfile
                case v of
                        Left _ -> delayed $ waiturl urlfile
                        Right url -> ifM (assistantListening url)
index 420e1efdab93416457b423eb3485bc2f5d9f94fc..4cbc79ec613a3889a0cd23cf1f11708d7878be19 100644 (file)
@@ -224,8 +224,8 @@ genSshKeyPair = withTmpDir (literalOsPath "git-annex-keygen") $ \dir -> do
        unless ok $
                giveup "ssh-keygen failed"
        SshKeyPair
-               <$> readFile (fromOsPath (dir </> literalOsPath "key.pub"))
-               <*> readFile (fromOsPath (dir </> literalOsPath "key"))
+               <$> readFileString (dir </> literalOsPath "key.pub")
+               <*> readFileString (dir </> literalOsPath "key")
 
 {- Installs a ssh key pair, and sets up ssh config with a mangled hostname
  - that will enable use of the key. This way we avoid changing the user's
@@ -255,7 +255,7 @@ installSshKeyPair sshkeypair sshdata = do
                writeFileProtected (sshdir </> sshPrivKeyFile sshdata)
                        (sshPrivKey sshkeypair)
        unlessM (doesFileExist $ sshdir </> sshPubKeyFile sshdata) $
-               writeFile (fromOsPath (sshdir </> sshPubKeyFile sshdata))
+               writeFileString (sshdir </> sshPubKeyFile sshdata)
                        (sshPubKey sshkeypair)
 
        setSshConfig sshdata
@@ -277,8 +277,10 @@ sshPubKeyFile sshdata = sshPrivKeyFile sshdata <> literalOsPath ".pub"
 setupSshKeyPair :: SshData -> IO (SshData, SshKeyPair)
 setupSshKeyPair sshdata = do
        sshdir <- sshDir
-       mprivkey <- catchMaybeIO $ readFile (fromOsPath (sshdir </> sshPrivKeyFile sshdata))
-       mpubkey <- catchMaybeIO $ readFile (fromOsPath (sshdir </> sshPubKeyFile sshdata))
+       mprivkey <- catchMaybeIO $ readFileString
+               (sshdir </> sshPrivKeyFile sshdata)
+       mpubkey <- catchMaybeIO $ readFileString
+               (sshdir </> sshPubKeyFile sshdata)
        keypair <- case (mprivkey, mpubkey) of
                (Just privkey, Just pubkey) -> return $ SshKeyPair
                        { sshPubKey = pubkey
@@ -330,15 +332,15 @@ setSshConfig :: SshData -> [(String, String)] -> IO SshData
 setSshConfig sshdata config = do
        sshdir <- sshDir
        createDirectoryIfMissing True sshdir
-       let configfile = fromOsPath (sshdir </> literalOsPath "config")
-       unlessM (catchBoolIO $ isInfixOf mangledhost <$> readFile configfile) $ do
-               appendFile configfile $ unlines $
+       let configfile = sshdir </> literalOsPath "config"
+       unlessM (catchBoolIO $ isInfixOf mangledhost <$> readFileString configfile) $ do
+               appendFileString configfile $ unlines $
                        [ ""
                        , "# Added automatically by git-annex"
                        , "Host " ++ mangledhost
                        ] ++ map (\(k, v) -> "\t" ++ k ++ " " ++ v)
                                (settings ++ config)
-               setSshConfigMode (toOsPath configfile)
+               setSshConfigMode configfile
 
        return $ sshdata
                { sshHostName = T.pack mangledhost
index ca6d5b3adacf68ee8c2f0451bb7e591635c44ed5..1d7c05a5d8512b204be84c81c6bd998268aaf78e 100644 (file)
@@ -160,7 +160,7 @@ upgradeToDistribution newdir cleanup distributionfile = do
                unlessM (boolSystem (fromOsPath program) [Param "version"]) $
                        giveup "New git-annex program failed to run! Not using."
                pf <- programFile
-               liftIO $ writeFile (fromOsPath pf) (fromOsPath program)
+               liftIO $ writeFileString pf (fromOsPath program)
        
 #ifdef darwin_HOST_OS
        {- OS X uses a dmg, so mount it, and copy the contents into place. -}
@@ -281,7 +281,7 @@ installBase = "git-annex." ++
 deleteFromManifest :: OsPath -> IO ()
 deleteFromManifest dir = do
        fs <- map (\f -> dir </> toOsPath f) . lines 
-               <$> catchDefaultIO "" (readFile (fromOsPath manifest))
+               <$> catchDefaultIO "" (readFileString manifest)
        mapM_ (removeWhenExistsWith removeFile) fs
        removeWhenExistsWith removeFile manifest
        removeEmptyRecursive dir
index 0d6b6f1eb337064e7939ab9c5b7ee35e810017f4..4574b0fe536936f578db7a8a429683cb12f24585 100644 (file)
@@ -185,7 +185,7 @@ getAndroidCameraRepositoryR = do
   where
        addignore = do
                liftIO $ unlessM (doesFileExist $ literalOsPath ".gitignore") $
-                       writeFile ".gitignore" ".thumbnails"
+                       writeFileString (literalOsPath ".gitignore") ".thumbnails"
                void $ inRepo $
                        Git.Command.runBool [Param "add", File ".gitignore"]
 
index 0f0a76584e4f87249b2437ad58b9537150a44641..a32a05f069b88669fd304b5bccf1e138561f6375 100644 (file)
@@ -74,5 +74,5 @@ getLogR :: Handler Html
 getLogR = page "Logs" Nothing $ do
        logfile <- liftAnnex $ fromRepo gitAnnexDaemonLogFile
        logs <- liftIO $ listLogs (fromOsPath logfile)
-       logcontent <- liftIO $ concat <$> mapM readFile logs
+       logcontent <- liftIO $ concat <$> mapM (readFileString . toOsPath) logs
        $(widgetFile "control/log")
index a6dcc0385319f4379f628ad1aa8c38dc3e80deab..bd42945118c05b6bf8160c151c82adb51a2e6dc7 100644 (file)
@@ -34,7 +34,7 @@ getLicenseR = do
                Just f -> customPage (Just About) $ do
                        -- no sidebar, just pages of legalese..
                        setTitle "License"
-                       license <- liftIO $ readFile (fromOsPath f)
+                       license <- liftIO $ readFileString f
                        $(widgetFile "documentation/license")
 
 getRepoGroupR :: Handler Html
index dc5e634016993297a46922352a879ecb998c172e..4b1a0594f929b99f621e78ac43de728306b6bcc1 100644 (file)
@@ -12,6 +12,7 @@ import Utility.Env.Basic
 import qualified Git.Version
 import Utility.SystemDirectory
 import Utility.OsPath
+import qualified Utility.FileIO as F
 
 import Control.Monad
 import Control.Applicative
@@ -93,7 +94,7 @@ getSshConnectionCaching = Config "sshconnectioncaching" . BoolConfig <$>
 setup :: IO ()
 setup = do
        createDirectoryIfMissing True (toOsPath tmpDir)
-       writeFile testFile "test file contents"
+       F.writeFileString (toOsPath testFile) "test file contents"
 
 cleanup :: IO ()
 cleanup = removeDirectoryRecursive (toOsPath tmpDir)
index b69fd828542bffcae143dab2ad044db49aa5b86a..ad066a89377e52d13d9a11ad1fbda79a1d085c6f 100644 (file)
@@ -74,7 +74,7 @@ install command = do
                , do
                        programfile <- inDestDir =<< programFile
                        createDirectoryIfMissing True (parentDir programfile)
-                       writeFile (fromOsPath programfile) command
+                       writeFileString programfile command
                )
 
 installUser :: FilePath -> IO ()
index c7566a5a9e132cf70d2c4770f54a26ceb8315e1d..b7223fdfa389566d83806679577328e637e1d715 100644 (file)
@@ -148,7 +148,7 @@ makeinfos updated changelogversion = do
                                        , distributionReleasedate = now
                                        , distributionUrgentUpgrade = Just "6.20180626"
                                        }
-                               liftIO $ writeFile (fromOsPath infofile) $ formatInfoFile d
+                               liftIO $ writeFileString infofile $ formatInfoFile d
                                void $ inRepo $ runBool [Param "add", File (fromOsPath infofile)]
                                signFile infofile
                                signFile f
@@ -173,7 +173,7 @@ makeinfos updated changelogversion = do
        -- Check for out of date info files.
        infos <- liftIO $ filter (literalOsPath ".info" `OS.isSuffixOf`)
                <$> emptyWhenDoesNotExist (dirContentsRecursive $ literalOsPath "git-annex")
-       ds <- liftIO $ forM infos (readish <$$> readFile . fromOsPath)
+       ds <- liftIO $ forM infos (readish <$$> readFileString)
        let dis = zip infos ds
        let ood = filter outofdate dis
        return ood
index c081dd83d552b5863c77192b0e3d91e204c8b9b2..065ac3b1ea51a0c56d96631bf03026b3649395c0 100644 (file)
@@ -29,6 +29,7 @@ import Utility.FileMode
 import Utility.CopyFile
 import Utility.SystemDirectory
 import qualified Utility.OsString as OS
+import qualified Utility.FileIO as F
 
 mklibs :: OsPath -> a -> IO Bool
 mklibs top _installedbins = do
@@ -47,9 +48,9 @@ mklibs top _installedbins = do
 
        -- Various files used by runshell to set up env vars used by the
        -- linker shims.
-       writeFile (fromOsPath (top </> literalOsPath "libdirs"))
+       F.writeFileString (top </> literalOsPath "libdirs")
                (unlines (map fromOsPath libdirs'))
-       writeFile (fromOsPath (top </> literalOsPath "gconvdir")) $
+       F.writeFileString (top </> literalOsPath "gconvdir") $
                case gconvlibs of
                        [] -> ""
                        (p:_) -> fromOsPath (parentDir p)
@@ -171,7 +172,7 @@ installLinkerShim top linker exe = do
        link <- relPathDirToFile (top </> exedir) (top <> linker)
        unlessM (doesFileExist (top </> exelink)) $
                createSymbolicLink (fromOsPath link) (fromOsPath (top </> exelink))
-       writeFile (fromOsPath exe) $ unlines
+       F.writeFileString exe $ unlines
                [ "#!/bin/sh"
                , "exec \"$GIT_ANNEX_DIR/" ++ fromOsPath exelink ++ "\" --library-path \"$GIT_ANNEX_LD_LIBRARY_PATH\" \"$GIT_ANNEX_DIR/shimmed/" ++ fromOsPath base ++ "/" ++ fromOsPath base ++ "\" \"$@\""
                ]
index 8241ff8dd861f596675565560a852449224d5d5c..b2e1209878d0265583e88d11bbb9273217cfda29 100644 (file)
@@ -43,6 +43,7 @@ import Utility.Exception
 import Utility.Directory\r
 import Utility.SystemDirectory\r
 import Utility.OsPath\r
+import qualified Utility.FileIO as F\r
 import Build.BundledPrograms\r
 \r
 main = do\r
@@ -55,11 +56,11 @@ main = do
                mustSucceed "sh" [Param "-c", Param $ "zcat standalone/licences.gz > '" ++ license ++ "'"]\r
                webappscript <- vbsLauncher tmpdir "git-annex-webapp" "git annex webapp"\r
                autostartscript <- vbsLauncher tmpdir "git-annex-autostart" "git annex assistant --autostart"\r
-               let htmlhelp = fromOsPath $ tmpdir </> literalOsPath "git-annex.html"\r
-               writeFile htmlhelp htmlHelpText\r
-               let gitannexcmd = fromOsPath $ tmpdir </> literalOsPath "git-annex.cmd"\r
-               writeFile gitannexcmd "git annex %*"\r
-               writeFile nsifile $ makeInstaller\r
+               let htmlhelp = tmpdir </> literalOsPath "git-annex.html"\r
+               F.writeFileString htmlhelp htmlHelpText\r
+               let gitannexcmd = tmpdir </> literalOsPath "git-annex.cmd"\r
+               F.writeFileString gitannexcmd "git annex %*"\r
+               F.writeFileString (toOsPath nsifile) $ makeInstaller\r
                        gitannex gitannexcmd license htmlhelp (winPrograms ++ magicDLLs') magicShare'\r
                        [ webappscript, autostartscript ]\r
                mustSucceed "makensis" [File nsifile]\r
@@ -85,13 +86,13 @@ main = do
  - box. It expects to be passed the directory where git-annex is installed. -}\r
 vbsLauncher :: OsPath -> String -> String -> IO String\r
 vbsLauncher tmpdir basename cmd = do\r
-       let f = fromOsPath $ tmpdir </> toOsPath (basename ++ ".vbs")\r
-       writeFile f $ unlines\r
+       let f = tmpdir </> toOsPath (basename ++ ".vbs")\r
+       F.writeFileString f $ unlines\r
                [ "Set objshell=CreateObject(\"Wscript.Shell\")"\r
                , "objShell.CurrentDirectory = Wscript.Arguments.item(0)"\r
                , "objShell.Run(\"" ++ cmd ++ "\"), 0, False"\r
                ]\r
-       return f\r
+       return (fromOsPath f)\r
 \r
 gitannexprogram :: FilePath\r
 gitannexprogram = "git-annex.exe"\r
index e0e9e56bee20c7a6a191643cbed791032972e451..44e817170744e3efe9f4cefff9aa9b25019242f5 100644 (file)
@@ -180,19 +180,19 @@ installSkel topdir _basedir = do
 installSkelRest :: OsPath -> OsPath -> Bool -> IO ()
 #ifdef darwin_HOST_OS
 installSkelRest _topdir basedir _hwcaplibs = do
-       plist <- lines <$> readFile "standalone/osx/Info.plist.template"
+       plist <- lines <$> F.readFileString (literalOsPath "standalone/osx/Info.plist.template")
        version <- getVersion
-       writeFile (fromOsPath (basedir </> literalOsPath "Contents" </> literalOsPath "Info.plist"))
+       F.writeFileString (basedir </> literalOsPath "Contents" </> literalOsPath "Info.plist")
                (unlines (map (expandversion version) plist))
   where
        expandversion v l = replace "GIT_ANNEX_VERSION" v l
 #else
 installSkelRest topdir _basedir hwcaplibs = do
-       runshell <- lines <$> readFile "standalone/linux/skel/runshell"
+       runshell <- lines <$> F.readFileString (literalOsPath "standalone/linux/skel/runshell")
        -- GIT_ANNEX_PACKAGE_INSTALL can be set by a distributor and
        -- runshell will be modified
        gapi <- getEnv "GIT_ANNEX_PACKAGE_INSTALL"
-       writeFile (fromOsPath (topdir </> literalOsPath "runshell"))
+       F.writeFileString (topdir </> literalOsPath "runshell")
                (unlines (map (expandrunshell gapi) runshell))
        modifyFileMode
                (topdir </> literalOsPath "runshell")
index f20972fa8f5c48fee29006969bb64b9b0693175d..c556f7ac2570362b8780e4ae161c26f0d1497dbe 100644 (file)
@@ -1,6 +1,7 @@
 {- Tests the system and generates SysConfig. -}
 
 {-# OPTIONS_GHC -fno-warn-tabs #-}
+{-# LANGUAGE OverloadedStrings #-}
 
 module Build.TestConfig where
 
@@ -9,6 +10,7 @@ import Utility.Monad
 import Utility.SafeCommand
 import Utility.SystemDirectory
 import Utility.OsPath
+import qualified Utility.FileIO as F
 
 import System.IO
 
@@ -42,7 +44,7 @@ instance Show Config where
                valuetype (MaybeBoolConfig _) = "Maybe Bool"
 
 writeSysConfig :: [Config] -> IO ()
-writeSysConfig config = writeFile "Build/SysConfig" body
+writeSysConfig config = F.writeFileString (literalOsPath "Build/SysConfig") body
   where
        body = unlines $ header ++ map show config ++ footer
        header = [
@@ -100,12 +102,16 @@ findCmdPath k command = do
        ifM (inSearchPath command)
                ( return $ Config k $ MaybeStringConfig $ Just command
                , do
-                       r <- getM find ["/usr/sbin", "/sbin", "/usr/local/sbin"]
+                       r <- getM find
+                               [ literalOsPath "/usr/sbin"
+                               , literalOsPath "/sbin"
+                               , literalOsPath "/usr/local/sbin"
+                               ]
                        return $ Config k $ MaybeStringConfig r
                )
   where
        find d =
-               let f = toOsPath d </> toOsPath command
+               let f = d </> toOsPath command
                in ifM (doesFileExist f)
                        ( return (Just (fromOsPath f))
                        , return Nothing
index 3552814116ec39fd72bcf98e2671fd2f7260e391..762714e89fe5e31f7b27937f3d568537d004f750 100644 (file)
@@ -51,7 +51,7 @@ getVersion = do
        
 getChangelogVersion :: IO Version
 getChangelogVersion = do
-       changelog <- readFile "CHANGELOG"
+       changelog <- F.readFileString (literalOsPath "CHANGELOG")
        let verline = takeWhile (/= '\n') changelog
        return $ middle (words verline !! 1)
   where
index 3534e21e63ce7dc883a3e58d27a188e8641da8da..cd244c6195f5bec1be2e65a554616d92cc6a81ab 100644 (file)
@@ -178,7 +178,7 @@ runFuzzAction :: FuzzAction -> Annex ()
 runFuzzAction (FuzzAdd (FuzzFile f)) = do
        createWorkTreeDirectory (parentDir (toOsPath f))
        n <- liftIO (getStdRandom random :: IO Int)
-       liftIO $ writeFile f $ show n ++ "\n"
+       liftIO $ writeFileString (toOsPath f) $ show n ++ "\n"
 runFuzzAction (FuzzDelete (FuzzFile f)) = liftIO $
        removeWhenExistsWith removeFile (toOsPath f)
 runFuzzAction (FuzzMove (FuzzFile src) (FuzzFile dest)) = liftIO $
index 613c9dd0f8da599c8a57f5687d720fea44b8d7de..7b66a2b5077613b7e33dc8597a8272e7fdea7102 100644 (file)
@@ -183,7 +183,7 @@ getFeed o url st =
                                        next $ return True
        
        debugfeedcontent tmpf msg = do
-               feedcontent <- liftIO $ readFile tmpf
+               feedcontent <- liftIO $ readFileString (toOsPath tmpf)
                fastDebug "Command.ImportFeed" $ unlines
                        [ "start of feed content"
                        , feedcontent
@@ -611,7 +611,7 @@ checkFeedBroken url = checkFeedBroken' url =<< feedState url
 checkFeedBroken' :: URLString -> OsPath -> Annex Bool
 checkFeedBroken' url f = do
        prev <- maybe Nothing readish
-               <$> liftIO (catchMaybeIO $ readFile (fromOsPath f))
+               <$> liftIO (catchMaybeIO $ readFileString f)
        now <- liftIO getCurrentTime
        case prev of
                Nothing -> do
index 7771014504aaa661e1dc4ccb927fdd2605836399..c83babd4b92d539e8ba662d1ec6427b67225b18e 100644 (file)
@@ -55,7 +55,7 @@ start = startingNoMessage (ActionItemOther Nothing) $ do
                                <$> fromRepo gitAnnexDir
                                <*> pure (literalOsPath "map.dot")
 
-                       liftIO $ writeFile (fromOsPath file) (drawMap rs trustmap umap)
+                       liftIO $ writeFileString file (drawMap rs trustmap umap)
                        next $
                                ifM (Annex.getRead Annex.fast)
                                        ( runViewer file []
index 36357c43982182a35a7dc1fc3de1941416c11aa9..60e7996e4290a0fb71b53d1e17607e6d740f8d73 100644 (file)
@@ -70,7 +70,7 @@ startsim' simfile = do
        let st = emptySimState rng (fromOsPath simdir)
        case simfile of
                Nothing -> startup simdir st []
-               Just f -> liftIO (readFile f) >>= \c -> 
+               Just f -> liftIO (readFileString (toOsPath f)) >>= \c -> 
                        case parseSimFile c of
                                Left err -> giveup err
                                Right cs -> startup simdir st cs
index 4679c598e54ca4ca1cdc211333be0ef358ff4fdc..c52b539a24427f7dfc841fe9f46a484592b0e23f 100644 (file)
@@ -49,7 +49,7 @@ start = do
        createAnnexDirectory $ parentDir f
        cfg <- getCfg
        descs <- uuidDescriptions
-       liftIO $ writeFile (fromOsPath f) $ genCfg cfg descs
+       liftIO $ writeFileString f $ genCfg cfg descs
        vicfg cfg f
        stop
 
@@ -65,7 +65,7 @@ vicfg curcfg f = do
        liftIO $ removeWhenExistsWith removeFile f
        case r of
                Left s -> do
-                       liftIO $ writeFile (fromOsPath f) s
+                       liftIO $ writeFileString f s
                        vicfg curcfg f
                Right newcfg -> setCfg curcfg newcfg
   where
index 02e5735d3bc2c321bf7192e024fef015adec945c..80801c3893770e6a872617a98ba11aba37352e6b 100644 (file)
@@ -90,7 +90,7 @@ start' allowauto o = do
                        ( if isJust (listenAddress o) || isJust (listenPort o)
                                then giveup "The assistant is already running, so --listen and --port cannot be used."
                                else do
-                                       url <- liftIO . readFile . fromOsPath
+                                       url <- liftIO . readFileString
                                                =<< fromRepo gitAnnexUrlFile
                                        liftIO $ if isJust listenAddress'
                                                then putStrLn url
index 14450fcc7256ae3ad1ca677910bb83d53ac745d3..7b7c6c49c7dcfbc2daed47a1e9386750de2be896 100644 (file)
@@ -32,4 +32,4 @@ programFile = userConfigFile (literalOsPath "program")
 noAnnexFileContent :: Maybe OsPath -> IO (Maybe String)
 noAnnexFileContent repoworktree = case repoworktree of
        Nothing -> return Nothing
-       Just wt -> catchMaybeIO (readFile (fromOsPath (wt </> literalOsPath ".noannex")))
+       Just wt -> catchMaybeIO (readFileString (wt </> literalOsPath ".noannex"))
index 7307e46d5cf70a996c9287178ee7522e34697d9e..31b6b2edf8926d051b6c8f87694e5fbeb680eb6b 100644 (file)
@@ -18,7 +18,7 @@ readAutoStartFile :: IO [OsPath]
 readAutoStartFile = do
        f <- autoStartFile
        filter valid . nub . map (dropTrailingPathSeparator . toOsPath) . lines
-               <$> catchDefaultIO "" (readFile (fromOsPath f))
+               <$> catchDefaultIO "" (readFileString f)
   where
        -- Ignore any relative paths; some old buggy versions added eg "."
        valid = isAbsolute
@@ -30,7 +30,7 @@ modifyAutoStartFile func = do
        when (dirs' /= dirs) $ do
                f <- autoStartFile
                createDirectoryIfMissing True (parentDir f)
-               viaTmp (writeFile . fromRawFilePath . fromOsPath) f
+               viaTmp writeFileString f
                        (unlines (map fromOsPath dirs'))
 
 {- Adds a directory to the autostart file. If the directory is already
index c17eaa1bca91185ab7f9c6c261f6e600c2f99d28..2f38c4772514a61b189425b2ec6c6325b2d0690e 100644 (file)
@@ -70,7 +70,7 @@ deconfigureSmudgeFilter = do
        lf <- Annex.fromRepo Git.attributesLocal
        ls <- liftIO $ catchDefaultIO [] $ 
                map decodeBS . fileLines' <$> F.readFile' lf
-       liftIO $ writeFile (fromOsPath lf) $ unlines $
+       liftIO $ writeFileString lf $ unlines $
                filter (\l -> l `notElem` stdattr && not (null l)) ls
        unsetConfig (ConfigKey "filter.annex.smudge")
        unsetConfig (ConfigKey "filter.annex.clean")
index d3fce7bbd89208b15190b597fd276524311389e8..93e659f445b611b4910d11e55c42007c3bef008f 100644 (file)
@@ -264,7 +264,7 @@ reconcileStaged dbisnew qh = ifM isBareRepo
        ( return mempty
        , do
                gitindex <- inRepo currentIndexFile
-               indexcache <- fromOsPath <$> calcRepo' gitAnnexKeysDbIndexCache
+               indexcache <- calcRepo' gitAnnexKeysDbIndexCache
                withTSDelta (liftIO . genInodeCache gitindex) >>= \case
                        Just cur -> readindexcache indexcache >>= \case
                                Nothing -> go cur indexcache =<< getindextree
@@ -278,7 +278,7 @@ reconcileStaged dbisnew qh = ifM isBareRepo
        lastindexref = Ref "refs/annex/last-index"
 
        readindexcache indexcache = liftIO $ maybe Nothing readInodeCache
-               <$> catchMaybeIO (readFile indexcache)
+               <$> catchMaybeIO (readFileString indexcache)
 
        getoldtree = fromMaybe emptyTree <$> inRepo (Git.Ref.sha lastindexref)
        
@@ -292,7 +292,7 @@ reconcileStaged dbisnew qh = ifM isBareRepo
                                        (Just (fromRef oldtree)) 
                                        (fromRef newtree)
                                        (procdiff mdfeeder)
-                       liftIO $ writeFile indexcache $ showInodeCache cur
+                       liftIO $ writeFileString indexcache $ showInodeCache cur
                        -- Storing the tree in a ref makes sure it does not
                        -- get garbage collected, and is available to diff
                        -- against next time.
index afbe4a5232006affd25599247b889f0ba934880d..cd91fd6461f8c18c0f4c6bd6b09dd1b271f55144 100644 (file)
@@ -280,7 +280,7 @@ adjustGitDirFile loc = fromMaybe loc <$> adjustGitDirFile' loc
 adjustGitDirFile' :: RepoLocation -> IO (Maybe RepoLocation)
 adjustGitDirFile' loc@(Local {}) = do
        let gd = gitdir loc
-       c <- firstLine <$> catchDefaultIO "" (readFile (fromOsPath gd))
+       c <- firstLine <$> catchDefaultIO "" (readFileString gd)
        if gitdirprefix `isPrefixOf` c
                then do
                        top <- takeDirectory <$> absPath gd
index e5a67bda7df8c4a9e0129787ceeea79d5b4970f9..d1c32fd189c381dd6bf486e4f3633e819fc983e4 100644 (file)
@@ -59,7 +59,7 @@ hookWrite h r = ifM (doesFileExist f)
        f = hookFile h r
        go = do
                -- On Windows, using a ByteString as the file content
-               -- avoids the newline translation done by writeFile.
+               -- avoids the newline translation done by writeFileString.
                -- Hook scripts on Windows could use CRLF endings, but
                -- they typically use unix newlines, which does work there
                -- and makes the repository more portable.
@@ -85,11 +85,11 @@ data ExpectedContent = UnexpectedContent | ExpectedContent | OldExpectedContent
 
 expectedContent :: Hook -> Repo -> IO ExpectedContent
 expectedContent h r = do
-       -- Note that on windows, this readFile does newline translation,
+       -- Note that on windows, this readFileString does newline translation,
        -- and so a hook file that has CRLF will be treated the same as one
        -- that has LF. That is intentional, since users may have a reason
        -- to prefer one or the other.
-       content <- readFile $ fromOsPath $ hookFile h r
+       content <- readFileString $ hookFile h r
        return $ if content == hookScript h
                then ExpectedContent
                else if any (content ==) (hookOldScripts h)
index 4d2a2e907b4d0b43bd2b59332ecf1c14b04fd51a..d39f410074e47981c42b1da512effad9c275d9d2 100644 (file)
@@ -50,7 +50,7 @@ looseObjectFile r sha = objectsDir r </> toOsPath prefix </> toOsPath rest
 
 listAlternates :: Repo -> IO [FilePath]
 listAlternates r = catchDefaultIO [] $
-       lines <$> readFile (fromOsPath alternatesfile)
+       lines <$> readFileString alternatesfile
   where
        alternatesfile = objectsDir r </> literalOsPath "info" </> literalOsPath "alternates"
 
index 2f1c31fe710fd6c9880918aa3b00c5bfc1c7825c..246b40ed8c92b943df55425d067f035325c18807 100644 (file)
@@ -269,7 +269,7 @@ explodePackedRefsFile r = do
                let dest = gitd </> toOsPath (fromRef' ref)
                createDirectoryUnder [gitd] (parentDir dest)
                unlessM (doesFileExist dest) $
-                       writeFile (fromOsPath dest) (fromRef sha)
+                       writeFileString dest (fromRef sha)
 
 packedRefsFile :: Repo -> OsPath
 packedRefsFile r = localGitDir r </> literalOsPath "packed-refs"
@@ -472,7 +472,7 @@ preRepair :: Repo -> IO ()
 preRepair g = do
        unlessM (validhead <$> catchDefaultIO "" (decodeBS <$> safeReadFile headfile)) $ do
                removeWhenExistsWith removeFile headfile
-               writeFile (fromOsPath headfile) "ref: refs/heads/master"
+               writeFileString headfile "ref: refs/heads/master"
        explodePackedRefsFile g
        unless (repoIsLocalBare g) $
                void $ tryIO $ allowWrite $ indexFile g
index 882dc253691f443347e46834a0883930cdf4301a..71a5baeb1c307b5b903abbf74469b9349ded4d85 100644 (file)
@@ -38,7 +38,7 @@ writeLogFile :: OsPath -> String -> Annex ()
 writeLogFile f c = createDirWhenNeeded f $ viaTmp writelog f c
   where
        writelog tmp c' = do
-               liftIO $ writeFile (fromOsPath tmp) c'
+               liftIO $ writeFileString tmp c'
                setAnnexFilePerm tmp
 
 -- | Runs the action with a handle connected to a temp file.
index b938491092f7376879e1393d0b01948bc451c757..3234af249395949b0ed155666dfba27f25328f36 100644 (file)
@@ -45,7 +45,7 @@ readFsckResults :: UUID -> Annex FsckResults
 readFsckResults u = do
        logfile <- fromRepo $ gitAnnexFsckResultsLog u
        liftIO $ catchDefaultIO (FsckFoundMissing S.empty False) $
-               deserializeFsckResults <$> readFile (fromOsPath logfile)
+               deserializeFsckResults <$> readFileString logfile
 
 deserializeFsckResults :: String -> FsckResults
 deserializeFsckResults = deserialize . lines
index 3e3c4395989ad9035f2d97f0ecce3595e34e4360..d63391c81439e4b6d450970666179e62f6b8aeeb 100644 (file)
@@ -55,7 +55,7 @@ streamRestageLog finalizer processor = do
                        ifM (doesPathExist oldf)
                                ( do
                                        h <- F.openFile oldf AppendMode
-                                       hPutStr h =<< readFile (fromOsPath logf)
+                                       hPutStr h =<< readFileString logf
                                        hClose h
                                        liftIO $ removeWhenExistsWith removeFile logf
                                , moveFile logf oldf
index 6727fdd316d9d9185e72de38eee425f6593fff9b..7bd839a545ff1ab462d3e693ab2c2bd0e9d13326 100644 (file)
@@ -63,9 +63,9 @@ scheduleChange u a = scheduleSet u . S.toList . a =<< scheduleGet u
 
 getLastRunTimes :: Annex (M.Map ScheduledActivity LocalTime)
 getLastRunTimes = do
-       f <- fromOsPath <$> fromRepo gitAnnexScheduleState
+       f <- fromRepo gitAnnexScheduleState
        liftIO $ fromMaybe M.empty
-               <$> catchDefaultIO Nothing (readish <$> readFile f)
+               <$> catchDefaultIO Nothing (readish <$> readFileString f)
 
 setLastRunTime :: ScheduledActivity -> LocalTime -> Annex ()
 setLastRunTime activity lastrun = do
index 85a5f7b8242978d3dd8e0e8dead4cb1a1f2e5370..e0beadab539aa764aeb2f81f770b295ef1ca3373 100644 (file)
@@ -263,7 +263,7 @@ writeTransferInfoFile info tfile = writeLogFile tfile $ writeTransferInfo info
 -- after it's been created with the right perms by writeTransferInfoFile.
 updateTransferInfoFile :: TransferInfo -> OsPath -> IO ()
 updateTransferInfoFile info tfile = 
-       writeFile (fromOsPath tfile) $ writeTransferInfo info
+       writeFileString tfile $ writeTransferInfo info
 
 {- File format is a header line containing the startedTime and any
  - bytesComplete value. Followed by a newline and the associatedFile.
index 14ee8dcd3715676caa44fb7744bcb5ef74fce7a1..838471f14edadffaacfc0b01cbdcaf0035a2ce42 100644 (file)
@@ -54,8 +54,8 @@ removeView v = writeViews =<< filter (/= v) <$> recentViews
 
 recentViews :: Annex [View]
 recentViews = do
-       f <- fromOsPath <$> fromRepo gitAnnexViewLog
-       liftIO $ mapMaybe readish . lines <$> catchDefaultIO [] (readFile f)
+       f <- fromRepo gitAnnexViewLog
+       liftIO $ mapMaybe readish . lines <$> catchDefaultIO [] (readFileString f)
 
 {- Gets the currently checked out view, if there is one. 
  -
index 3773ed9172c6ed072104be58a62dc1b81cf623c7..e32b263b98a4b429afc6bb6a4b80e09e9f1af10f 100644 (file)
@@ -33,7 +33,7 @@ withCheckedFiles check d locations k a = go $ locations d k
                let chunkcount = f ++ Legacy.chunkCount
                ifM (check chunkcount)
                        ( do
-                               chunks <- Legacy.listChunks f <$> readFile chunkcount
+                               chunks <- Legacy.listChunks f <$> readFileString (toOsPath chunkcount)
                                ifM (allM check chunks)
                                        ( a chunks , return False )
                        , do
@@ -85,7 +85,7 @@ storeHelper repotop finalizer key storer tmpdir destdir = do
        recorder f s = do
                let f' = toOsPath f
                void $ tryIO $ allowWrite f'
-               writeFile f s
+               writeFileString f' s
                void $ tryIO $ preventWrite f'
 
 store :: FilePath -> ChunkSize -> (OsPath -> OsPath -> IO ()) -> Key -> L.ByteString -> MeterUpdate -> FilePath -> FilePath -> IO ()
index 2f0cebf188e91bee94b9c9dfe76a6e6a6e32eb53..c58ae362b41345022436f984e1e2a47005bf3640 100644 (file)
@@ -213,7 +213,7 @@ createClient configdir furl = do
 
 writeSharedConvergenceSecret :: TahoeConfigDir -> SharedConvergenceSecret -> IO ()
 writeSharedConvergenceSecret configdir scs = 
-       writeFile (fromOsPath (convergenceFile configdir))
+       writeFileString (convergenceFile configdir)
                (unlines [scs])
 
 {- The tahoe daemon writes the convergenceFile shortly after it starts
@@ -223,11 +223,11 @@ writeSharedConvergenceSecret configdir scs =
 getSharedConvergenceSecret :: TahoeConfigDir -> IO SharedConvergenceSecret
 getSharedConvergenceSecret configdir = go (60 :: Int)
   where
-       f = fromOsPath $ convergenceFile configdir
+       f = convergenceFile configdir
        go n
-               | n == 0 = giveup $ "tahoe did not write " ++ f ++ " after 1 minute. Perhaps the daemon failed to start?"
+               | n == 0 = giveup $ "tahoe did not write " ++ fromOsPath f ++ " after 1 minute. Perhaps the daemon failed to start?"
                | otherwise = do
-                       v <- catchMaybeIO (readFile f)
+                       v <- catchMaybeIO (readFileString f)
                        case v of
                                Just s | "\n" `isSuffixOf` s || "\r" `isSuffixOf` s ->
                                        return $ takeWhile (`notElem` ("\n\r" :: String)) s
diff --git a/Test.hs b/Test.hs
index 62cb88c10fbf52ee6169986b302adb65f46c6188..43a15f89524bce7a10891ed5a434e0e08fb6a53c 100644 (file)
--- a/Test.hs
+++ b/Test.hs
@@ -556,8 +556,8 @@ test_magic = intmpclonerepo $ do
 #ifdef WITH_MAGICMIME
        git "config" ["annex.largefiles", "mimeencoding=binary"]
                "git config annex.largefiles"
-       writeFile "binary" "\127"
-       writeFile "text" "test\n" 
+       writeFileString (literalOsPath "binary") "\127"
+       writeFileString (literalOsPath "text") "test\n" 
        git_annex "add" ["binary", "text"]
                "git-annex add with mimeencoding in largefiles"
        git_annex "sync" ["--no-content"]
@@ -879,7 +879,7 @@ test_lock = intmpclonerepo $ do
        changecontent annexedfile
        git "add" [annexedfile] "add of modified file"
        runchecks [checkregularfile, checkwritable] annexedfile
-       c <- readFile annexedfile
+       c <- readFileString (toOsPath annexedfile)
        assertEqual "content of modified file" c (changedcontent annexedfile)
        git_annex_shouldfail "drop" [annexedfile]
                "drop with no known copy of modified file should not be allowed"
@@ -921,7 +921,7 @@ test_edit' precommit = intmpclonerepo $ do
                then git_annex "pre-commit" [] "pre-commit"
                else git "commit" ["-q", "-m", "contentchanged"] "git commit of edited file"
        runchecks [checkregularfile, checkwritable] annexedfile
-       c <- readFile annexedfile
+       c <- readFileString (toOsPath annexedfile)
        assertEqual "content of modified file" c (changedcontent annexedfile)
        git_annex_shouldfail "drop" [annexedfile] "drop no known copy of modified file should not be allowed"
 
@@ -947,7 +947,7 @@ test_fix = intmpclonerepo $ unlessM (hasUnlockedFiles <$> getTestMode) $ do
        git "mv" [annexedfile, subdir] "git mv"
        git_annex "fix" [newfile] "fix of moved file"
        runchecks [checklink, checkunwritable] newfile
-       c <- readFile newfile
+       c <- readFileString (toOsPath newfile)
        assertEqual "content of moved file" c (content annexedfile)
   where
        subdir = "s"
@@ -1069,7 +1069,8 @@ test_migrate' usegitattributes = intmpclonerepo $ do
        annexed_present sha1annexedfile
        if usegitattributes
                then do
-                       writeFile ".gitattributes" "* annex.backend=SHA1"
+                       writeFileString (literalOsPath ".gitattributes")
+                               "* annex.backend=SHA1"
                        git_annex "migrate" [sha1annexedfile]
                                "migrate sha1annexedfile"
                        git_annex "migrate" [annexedfile]
@@ -1085,7 +1086,8 @@ test_migrate' usegitattributes = intmpclonerepo $ do
        checkbackend sha1annexedfile backendSHA1
 
        -- check that reversing a migration works
-       writeFile ".gitattributes" "* annex.backend=SHA256"
+       writeFileString (literalOsPath ".gitattributes")
+               "* annex.backend=SHA256"
        git_annex "migrate" [sha1annexedfile] "migrate sha1annexedfile"
        git_annex "migrate" [annexedfile] "migrate annexedfile"
        annexed_present annexedfile
@@ -1531,7 +1533,7 @@ test_nonannexed_file_conflict_resolution = do
                length v == 1
                        @? (what ++ " too many variant files in: " ++ show v)
                conflictor `elem` l @? (what ++ " conflictor file missing in: " ++ show l)
-               s <- catchMaybeIO $ readFile $ fromOsPath $
+               s <- catchMaybeIO $ readFileString $
                        toOsPath d </> toOsPath conflictor
                s == Just nonannexed_content
                        @? (what ++ " wrong content for nonannexed file: " ++ show s)
@@ -2074,9 +2076,9 @@ test_export_import = intmpclonerepo $ do
        dircontains "import" (content "newimport3")
   where
        dircontains f v = do
-               let df = fromOsPath (literalOsPath "dir" </> stringToOsPath f)
-               ((v==) <$> readFile df)
-                       @? ("did not find expected content of " ++ df)
+               let df = literalOsPath "dir" </> stringToOsPath f
+               ((v==) <$> readFileString df)
+                       @? ("did not find expected content of " ++ fromOsPath df)
        writedir f = writecontent (fromOsPath (literalOsPath "dir" </> stringToOsPath f))
        -- When on an adjusted branch, this updates the master branch
        -- to match it, which is necessary since the master branch is going
@@ -2111,9 +2113,9 @@ test_export_import_subdir = intmpclonerepo $ do
        testexport
   where
        dircontains f v = do
-               let df = fromOsPath (literalOsPath "dir" </> toOsPath f)
-               ((v==) <$> readFile df)
-                       @? ("did not find expected content of " ++ df)
+               let df = literalOsPath "dir" </> toOsPath f
+               ((v==) <$> readFileString df)
+                       @? ("did not find expected content of " ++ fromOsPath df)
        
        subdir = "subdir"
        subannexedfile = fromOsPath $
index 3d0a96fa2f349eb09c1e3e30fb5f7ee0ca36a258..fee78b4875f70ce50494110fb60690bbd48ae204 100644 (file)
@@ -391,7 +391,7 @@ checkexists f =
 
 checkcontent :: FilePath -> Assertion
 checkcontent f = do
-       c <- Utility.Exception.catchDefaultIO "could not read file" $ readFile f
+       c <- Utility.Exception.catchDefaultIO "could not read file" $ readFileString (toOsPath f)
        assertEqual ("checkcontent " ++ f) (content f) c
 
 checkunwritable :: FilePath -> Assertion
@@ -415,7 +415,7 @@ checkdangling :: FilePath -> Assertion
 checkdangling f = ifM (annexeval Config.crippledFileSystem)
        ( return () -- probably no real symlinks to test
        , do
-               r <- tryIO $ readFile f
+               r <- tryIO $ readFileString (toOsPath f)
                case r of
                        Left _ -> return () -- expected; dangling link
                        Right _ -> assertFailure $ f ++ " was not a dangling link as expected"
@@ -675,9 +675,10 @@ writecontent :: FilePath -> String -> IO ()
 writecontent f c = go (10000000 :: Integer)
   where
        go ticsleft = do
-               oldmtime <- catchMaybeIO $ getModificationTime (toOsPath f)
-               writeFile f c
-               newmtime <- getModificationTime (toOsPath f)
+               let f' = toOsPath f
+               oldmtime <- catchMaybeIO $ getModificationTime f'
+               writeFileString f' c
+               newmtime <- getModificationTime f'
                if Just newmtime == oldmtime
                        then do
                                threadDelay 100000
index bd01cb5ab07741248b1c952a33b67204cd60cfe3..215179cc9a903ef8aa93cd25725b538ce0871543 100644 (file)
@@ -87,7 +87,7 @@ locationLogs = do
 inject :: OsPath -> OsPath -> Annex ()
 inject source dest = do
        old <- fromRepo olddir
-       new <- liftIO (readFile $ fromOsPath $ old </> source)
+       new <- liftIO $ readFileString (old </> source)
        Annex.Branch.change (Annex.Branch.RegardingUUID []) dest $ \prev -> 
                encodeBL $ unlines $ nub $ lines (decodeBL prev) ++ lines new
 
@@ -141,7 +141,7 @@ gitAttributesUnWrite repo = do
        whenM (doesFileExist attributes) $ do
                c <- map decodeBS . fileLines'
                        <$> F.readFile' attributes
-               liftIO $ viaTmp (writeFile . fromOsPath) attributes 
+               liftIO $ viaTmp writeFileString attributes 
                        (unlines $ filter (`notElem` attrLines) c)
                Git.Command.run [Param "add", File (fromOsPath attributes)] repo
 
index caabe13d2f6ef7a5b59f95d18ba669b3a8efc668..218096f2082997117b74dd2a634b26bf253f7eba 100644 (file)
@@ -136,7 +136,7 @@ updateSmudgeFilter = do
                <$> catchDefaultIO "" (F.readFile' lf)
        let ls' = removedotfilter ls
        when (ls /= ls') $
-               liftIO $ writeFile (fromOsPath lf) (unlines ls')
+               liftIO $ writeFileString lf (unlines ls')
   where
        removedotfilter ("* filter=annex":".* !filter":rest) =
                "* filter=annex" : removedotfilter rest
index a95503f0d2277ad66f183274650eef3967c05357..bd654da7ddab0ce429528d1f9f76fee792049bce 100644 (file)
@@ -121,9 +121,9 @@ lockPidFile pidfile = do
        unlessM (isNothing <$> checkDaemon pidfile)
                alreadyRunning
        pid <- getPID
-       writeFile (fromOsPath pidfile) (show pid)
+       writeFileString pidfile (show pid)
        lckfile <- winLockFile pid pidfile
-       writeFile (fromOsPath lckfile) ""
+       writeFileString lckfile ""
        void $ lockExclusive lckfile
 #endif
 
@@ -147,7 +147,7 @@ checkDaemon pidfile = bracket setup cleanup go
        cleanup Nothing = return ()
        go (Just fd) = catchDefaultIO Nothing $ do
                locked <- getLock fd (ReadLock, AbsoluteSeek, 0, 0)
-               p <- readish <$> readFile (fromOsPath pidfile)
+               p <- readish <$> readFileString pidfile
                return (check locked p)
        go Nothing = return Nothing
 
@@ -161,7 +161,7 @@ checkDaemon pidfile = bracket setup cleanup go
                        "; expected " ++ show pid ++ " )"
 #else
 checkDaemon pidfile = maybe (return Nothing) (check . readish)
-       =<< catchMaybeIO (readFile (fromOsPath pidfile))
+       =<< catchMaybeIO (readFileString pidfile)
   where
        check Nothing = return Nothing
        check (Just pid) = do
index a4d5cc5a20b6a322915814d971d01afeac1b81c6..8c7de891eaa7bce36dc40bbf258ccc123b6d6a3a 100644 (file)
@@ -171,7 +171,7 @@ setSticky f = modifyFileMode f $ addModes [stickyMode]
  - When possible, this is done using the umask.
  -
  - On a filesystem that does not support file permissions, this is the same
- - as writeFile.
+ - as writeFileString.
  -}
 writeFileProtected :: OsPath -> String -> IO ()
 writeFileProtected file content = writeFileProtected' file 
index 71ec3a3c7b395b634b259afabe385d1146a895cb..8fe6cbf9dcb2e53d4bd5186b47ccfdb00832e229 100644 (file)
@@ -75,7 +75,7 @@ buildDesktopMenuFile d = unlines ("[Desktop Entry]" : map keyvalue d) ++ "\n"
 writeDesktopMenuFile :: DesktopEntry -> OsPath -> IO ()
 writeDesktopMenuFile d file = do
        createDirectoryIfMissing True (takeDirectory file)
-       writeFile (fromOsPath file) $ buildDesktopMenuFile d
+       writeFileString file $ buildDesktopMenuFile d
 
 {- Path to use for a desktop menu file, in either the systemDataDir or
  - the userDataDir -}
index 7e1b18aa35fd46a5c29721aa5265889fc95a851d..08c4a6c8a62374f22b543cc7d996c11054b5468d 100644 (file)
@@ -234,7 +234,7 @@ noTSDelta = TSDelta (pure 0)
 writeSentinalFile :: SentinalFile -> IO ()
 writeSentinalFile s = do
        F.writeFile' (sentinalFile s) mempty
-       maybe noop (writeFile (fromOsPath (sentinalCacheFile s)) . showInodeCache)
+       maybe noop (writeFileString (sentinalCacheFile s) . showInodeCache)
                =<< genInodeCache (sentinalFile s) noTSDelta
 
 data SentinalStatus = SentinalStatus
@@ -263,7 +263,7 @@ checkSentinalFile s = do
                                Just new -> return $ calc old new
   where
        loadoldcache = catchDefaultIO Nothing $
-               readInodeCache <$> readFile (fromOsPath (sentinalCacheFile s))
+               readInodeCache <$> readFileString (sentinalCacheFile s)
        gennewcache = genInodeCache (sentinalFile s) noTSDelta
        calc (InodeCache (InodeCachePrim oldinode oldsize oldmtime)) (InodeCache (InodeCachePrim newinode newsize newmtime)) =
                SentinalStatus (not unchanged) tsdelta
index 2c480a354d373dd8246340e562850762063dab33..67cf78d62ebee8bb33c210d715a1e853c0751de4 100644 (file)
@@ -41,6 +41,7 @@ import Utility.Env.Set
 import Utility.Tmp
 import Utility.RawFilePath
 import Utility.OsPath
+import qualified Utility.FileIO as F
 import qualified Utility.LockFile.Posix as Posix
 
 import System.IO
@@ -77,7 +78,7 @@ mkPidLock = PidLock
 
 readPidLock :: PidLockFile -> IO (Maybe PidLock)
 readPidLock lockfile = (readish =<<)
-       <$> catchMaybeIO (readFile (fromOsPath lockfile))
+       <$> catchMaybeIO (F.readFileString lockfile)
 
 -- To avoid races when taking over a stale pid lock, a side lock is used.
 -- This is a regular posix exclusive lock.
@@ -214,7 +215,7 @@ linkToLock (Just _) src dest = do
                                        (CloseOnExecFlag True)
                                fdToHandle fd
                        let cleanup = hClose
-                       let go h = readFile (fromOsPath src) >>= hPutStr h
+                       let go h = F.readFileString src >>= hPutStr h
                        bracket setup cleanup go
                        getFileStatus dest'
   where
index ac98873ab12c8550729ab3d8dd663b74e795672d..c81ca21f28823133ec31966880ef1f01d06bd4f7 100644 (file)
@@ -110,7 +110,7 @@ fileLines' = map stripCR . S8.lines
 fileLines' = S8.lines
 #endif
 
--- One windows, writeFile does NewlineMode translation,
+-- On windows, writeFile does NewlineMode translation,
 -- adding CR before LF. When converting to ByteString, use this to emulate that.
 linesFile :: L.ByteString -> L.ByteString
 #ifndef mingw32_HOST_OS
index 0d43994f98e7fd6c466168d06e3f12afa65dc519..5f9b08909d1391b8b4f62d789163c42fac542f8e 100644 (file)
@@ -37,7 +37,7 @@ findShellCommand f = do
 #ifndef mingw32_HOST_OS
        defcmd
 #else
-       l <- catchDefaultIO Nothing $ headMaybe . lines <$> readFile (fromOsPath f)
+       l <- catchDefaultIO Nothing $ headMaybe . lines <$> readFileString f
        case l of
                Just ('#':'!':rest) -> case words rest of
                        [] -> defcmd
index c47cdfcb0bdabf938fa2ff4e80b7d97e106306c4..582f6849fc898d6a361d7a452b5286cf51bb5107 100644 (file)
@@ -49,13 +49,13 @@ openTmpFileIn dir template = F.openTempFile dir template
                let loc = ioeGetLocation e ++ " template " ++ decodeBS (fromOsPath template)
                in annotateIOError e loc Nothing Nothing
 
-{- Runs an action like writeFile, writing to a temp file first and
+{- Runs an action like writeFileString, writing to a temp file first and
  - then moving it into place. The temp file is stored in the same
  - directory as the final file to avoid cross-device renames.
  -
  - While this uses a temp file, the file will end up with the same
- - mode as it would when using writeFile, unless the writer action changes
- - it.
+ - mode as it would when using writeFileString, unless the writer action
+ - changes it.
  -}
 viaTmp :: (MonadMask m, MonadIO m) => (OsPath -> v -> m ()) -> OsPath -> v -> m ()
 viaTmp a file content = bracketIO setup cleanup use
index a49d7375a73e0532ff86eacf87916ddbe5daa3d8..05ece394fed4f8b976e12a6addd8c6c131efec72 100644 (file)
@@ -71,7 +71,7 @@ connectHiddenService (OnionAddress address) port = do
 addHiddenService :: AppName -> UserID -> UniqueIdent -> IO (OnionAddress, OnionPort)
 addHiddenService appname uid ident = do
        prepHiddenServiceSocketDir appname uid ident
-       ls <- lines <$> (readFile . fromOsPath =<< findTorrc)
+       ls <- lines <$> (readFileString =<< findTorrc)
        let portssocks = mapMaybe (parseportsock . separate isSpace) ls
        case filter (\(_, s) -> s == fromOsPath sockfile) portssocks of
                ((p, _s):_) -> waithiddenservice 1 p
@@ -80,7 +80,7 @@ addHiddenService appname uid ident = do
                        let newport = fromMaybe (error "internal") $ headMaybe $
                                filter (`notElem` map fst portssocks) highports
                        torrc <- findTorrc
-                       writeFile (fromOsPath torrc) $ unlines $
+                       writeFileString torrc $ unlines $
                                ls ++
                                [ ""
                                , "HiddenServiceDir " ++ fromOsPath (hiddenServiceDir appname uid ident)
@@ -112,7 +112,7 @@ addHiddenService appname uid ident = do
        waithiddenservice :: Int -> OnionPort -> IO (OnionAddress, OnionPort)
        waithiddenservice 0 _ = giveup "tor failed to create hidden service, perhaps the tor service is not running"
        waithiddenservice n p = do
-               v <- tryIO $ readFile $ fromOsPath $
+               v <- tryIO $ readFileString $
                        hiddenServiceHostnameFile appname uid ident
                case v of
                        Right s | ".onion\n" `isSuffixOf` s ->
@@ -152,7 +152,7 @@ hiddenServiceSocketFile appname uid ident =
 getHiddenServiceSocketFile :: AppName -> UserID -> UniqueIdent -> IO (Maybe OsPath)
 getHiddenServiceSocketFile _appname uid ident = 
        parse . map words . lines <$> catchDefaultIO "" 
-               (readFile . fromOsPath =<< findTorrc)
+               (readFileString =<< findTorrc)
   where
        parse [] = Nothing
        parse (("HiddenServiceDir":hsdir:[]):("HiddenServicePort":_hsport:hsaddr:[]):rest)